/****************************************************************************
 *
 * Copyright (C) 2003-2008 Los Alamos National Security, LLC
 *                         Packet Analytics Corporation
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License Version 2 as
 * published by the Free Software Foundation.  You may not use, modify or
 * distribute this program under any other version of the GNU General
 * Public License.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 *
 ****************************************************************************/
package nfse.dataset.netsensor;
import java.util.*;
import java.sql.*;

public class NetSensorStateMapping {

    private HashMap<String,Integer> idsByValue = new HashMap<String,Integer>(13);
    private HashMap<Integer,String> valuesByID = new HashMap<Integer,String>(13);
    private HashMap<Integer,String> descsByID = new HashMap<Integer,String>(13);
    
    public void init(Statement s) throws Exception {
        String sql = "select * from NetSensor_States";
        ResultSet rs = s.executeQuery(sql);
        while (rs.next()) {
            int id = rs.getInt("ID");
            String value = rs.getString("Label");
            String desc = rs.getString("Description");
            addEntry(id, value, desc);
        }
        rs.close();
    }
    
    public void addEntry(int id, String value, String description) {
        idsByValue.put(value, new Integer(id));
        valuesByID.put(new Integer(id), value);
        descsByID.put(new Integer(id),description);
    }
    
    public String getDescription(int id) {
        String temp = (String)descsByID.get(new Integer(id));
        return temp;
    }
    
    public String getDescription(String value) {
        Integer id = (Integer)idsByValue.get(value);
        String temp = (String)descsByID.get(id);
        return temp;
    }
    
    public String getValue(int id) {
        String temp = (String)valuesByID.get(new Integer(id));
        return temp;
    }
    
    public int getID(String value) {
        Integer val = ((Integer)idsByValue.get(value));
        if (val == null)
            return 0;
        int temp = val.intValue();
        return temp;
    }
    
    
}
